<?php
 /**
 +------------------------------------------------------------------------------
 * Request for controller,use $this->request->get();
 +------------------------------------------------------------------------------
 * @Version  3.0
 * @Author   WangXian
 * @E-mail    admin@loopx.cn
 * @package  ephp
 * @Creation  date 2011-1-14 下午03:47:37
 * @Modified  date 2011-1-14 下午03:47:37
 +------------------------------------------------------------------------------
 */
class Request
{
	/**
	 * assert variable is set?
	 * @param string $key
	 * @param string $default
	 */
    public function assert($key, $default = '')
    {
        return isset($key) ? $key : $default;
    }

    /**
     * Retrieve a member of the $_GET superglobal
     * If no $key is passed, returns the entire $_GET array.
     * @param string $key
     * @param mixed $default Default value to use if key not found
     * @return mixed Returns null if key does not exist
     */
    public function get($key = null, $default = '')
    {
        if (null === $key) return $_GET;
        return isset($_GET[$key]) ? $_GET[$key] : $default;
    }

    /**
     * Retrieve a member of the $_POST superglobal
     * If no $key is passed, returns the entire $_POST array.
     * @param string $key
     * @param mixed $default Default value to use if key not found
     * @return mixed Returns null if key does not exist
     */
    public function post($key = null, $default = '')
    {
        if (null === $key)  return $_POST;
        return isset($_POST[$key]) ? $_POST[$key] : $default;
    }

    /**
     * Retrieve a member of the $_COOKIE superglobal
     * If no $key is passed, returns the entire $_COOKIE array.
     * @param string $key
     * @param mixed $default Default value to use if key not found
     * @return mixed Returns null if key does not exist
     */
    public function cookie($key = null, $default = '')
    {
        if (null === $key) return $_COOKIE;
        return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default;
    }

    /**
     * Retrieve a member of the $_SERVER superglobal
     * If no $key is passed, returns the entire $_SERVER array.
     * @param string $key
     * @param mixed $default Default value to use if key not found
     * @return mixed Returns null if key does not exist
     */
    public function server($key = null, $default = '')
    {
        if (null === $key) return $_SERVER;
        return isset($_SERVER[$key]) ? $_SERVER[$key] : $default;
    }

    /**
     * Retrieve a member of the $_ENV superglobal
     * If no $key is passed, returns the entire $_ENV array.
     * @param string $key
     * @param mixed $default Default value to use if key not found
     * @return mixed Returns null if key does not exist
     */
    public function env($key = null, $default = '')
    {
        if (null === $key) return $_ENV;
        return isset($_ENV[$key]) ? $_ENV[$key] : $default;
    }

    /**
     * Get session
     * @param string $key
     * @param mixed $default
     * @return mixed
     */
    public function session($key = null, $default = '')
    {
    	isset($_SESSION) || session_start();
        if (null === $key)  return $_SESSION;
        return isset($_SESSION[$key]) ? $_SESSION[$key] : $default;
    }
}